<%-- 
    Document   : addSpecMCQ
    Created on : 06/10/2011, 12:12:52 PM
    Author     : s4200768
--%>

<script language="javascript"> 
    window.onload = begin;
    var Polltype;
    
    function changeType(type){
        Polltype= type;
    }
    
    function begin(){
        addBlank(1,10);
        enable(1,10);
        disable(3,10);
    }
    
    function addText(text, textbox){
        var box = document.getElementById(textbox);
        box.value = text;
    }
            
    function addBlank(start, end){
        for (var i=start; i<=end ; i++){
            addText('', 'ANSWER'+i);
                    
        }
    }
    
    function disable(start, end){
        for (var i=start; i<=end ; i++){
            addText('', 'P'+i);
            document.getElementById('ANSWER'+i).disabled = true;
            document.getElementById('C'+i).disabled = true;
            document.getElementById('P'+i).disabled = true;
                    
        }
    }
                  
    function enable(start, end){
        for (var i=start; i<=end ; i++){
            addText('1', 'P'+i);
            document.getElementById('ANSWER'+i).disabled = false;
            document.getElementById('C'+i).disabled = false;
            document.getElementById('P'+i).disabled = false;
        }
    }
    
    function isEnabled(){
        for (var i=1; i<=10 ; i++){
            var check = document.getElementById('ANSWER'+i).disabled;
            if (check == true){
                document.getElementById('ANSWER'+i).disabled=false;
                document.getElementById('P'+i).disabled=false;
                document.getElementById('C'+i).disabled=false;
                addText('1', 'P'+i);
                break;
            }
        }
        
    }
    
            
    function checkForm(){
        var question = document.getElementById('MCQuestion').value;
        if (question == ""){
            alert("Please fill in a question");
            return false;
        }
        for (var i=1 ; i<=10 ; i++){
            var current = document.getElementById('ANSWER'+i).value;
            var currentPoint = document.getElementById('P'+i).value;
            if (current != "" && currentPoint != "" ){
                return true;
            }
        }
        alert("Please fill in the answer field");
        return false;

    }
    

            
            
</script>

<style type="text/css">
    #thing{
        position:relative;
        left:70px;
        margin-top: 0px;
    }
    #i{
        margin-bottom:20px;
    }
    #buttons{

        position:relative;  
        bottom:70px;
        padding-top:155px;
        float:left;


    }

    #h{
        color:#006633;
        font-weight: bold;
    }

    #LForm{
        float:left;
        margin-top:0px;
        padding-top:0px;
    }

    #hh{
        margin-top:-5px;
    }

    #i1{
        padding-left: 21px;
        padding-right: 20px;
    }

    #i3{
        padding-left:36px;
        padding-right:35px;
    }

    #i4{
        padding-left:19px;
        padding-right:19px;
    }

    #butt{
        margin-top: 15px;
    }

</style>

<%@ include file="../header.jsp" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<link rel="stylesheet" type="text/css" href="../style.css"/>
<div id="content-container1">
    <div id="content">
        <!-- Content goes here -->
        <br />

        <div id="LForm">

            <form:form method="post" commandName="addSpec"><br />
                <%Object temps = request.getParameter("pid");%>


                <% int type = Integer.parseInt(request.getParameter("type"));
                    int tt = type;

                %>
                <% if (tt == 1) {
                %>
                <h3 id="hh">New Demographic Question</h3>
                <span hidden="true">
                    <form:input path='pollID' type='text' value='<%=temps%>'/>    
                    <form:input path='qStyle' type='text' value='<%=type%>'/>    
                </span>                

                <label><b>Enter Question Text: </b></label><br /><form:input path="questionText" NAME="MCQuestion" SIZE="40"  id="MCQuestion"/><BR><BR>

                <br />
                <label><b>Graph Type: </b></label><br />
                <form:select id="chart" path="style">
                    <option id="selected">Pie</option>
                    <option id="type1">Vertical Bar</option>
                    <option id="type2">Horizontal Bar</option>
                </form:select> <br />

                <div id="butt"><INPUT TYPE=SUBMIT value="Submit" onClick="return checkForm()">
                    <input type="button" onclick="addBlank(1,10),
                        enable(1,10),
                        disable(3,10)" 
                           id="Template5" value="Clear" />
                    <input type="button" onclick="isEnabled()" 
                           id="Template6" value="Add Field" /><br />
                </div>


                <% } else if (tt == 2) {%>
                <h3 id="hh">New Comparative Question</h3> 

                <label><b>Enter Question Text: </b></label><br /><form:input path="questionText" NAME="MCQuestion" SIZE="40"  id="MCQuestion"/><BR><BR>

                <span hidden="true">
                    <form:input path='pollID' type='text' value='<%=temps%>'/>    
                    <form:input path='qStyle' type='text' value='<%=type%>'/>    
                </span>                

                <label><b>Graph Type: </b></label><br />
                <form:select id="chart" path="style">
                    <option id="selected">Pie</option>
                    <option id="type1">Vertical Bar</option>
                    <option id="type2">Horizontal Bar</option>
                </form:select> <br />

                <div id="butt"><INPUT TYPE=SUBMIT value="Submit" onClick="return checkForm()">
                    <input type="button" onclick="addBlank(1,10),
                        enable(1,10),
                        disable(3,10)" 
                           id="Template5" value="Clear" />
                    <input type="button" onclick="isEnabled()" 
                           id="Template6" value="Add Field" /><br />
                </div>
                <%} else {%>
                <h3 id="hh">New Ranking Question</h3>

                <label><b>Enter Question Text: </b></label><br /><form:input path="questionText" NAME="MCQuestion" SIZE="40"  id="MCQuestion"/><BR><BR>

                <span hidden="true">
                    <form:input path='pollID' type='text' value='<%=temps%>'/>    
                    <form:input path='qStyle' type='text' value='<%=type%>'/>    
                </span>                

                <label><b>Graph Type: </b></label><br />
                <form:select id="chart" path="style">
                    <option id="selected">Pie</option>
                    <option id="type1">Vertical Bar</option>
                    <option id="type2">Horizontal Bar</option>
                </form:select> <br />

                <div id="butt"><INPUT TYPE=SUBMIT value="Submit" onClick="return checkForm()">
                    <input type="button" onclick="addBlank(1,10),
                        enable(1,10),
                        disable(3,10)" 
                           id="Template5" value="Clear" />
                    <input type="button" onclick="isEnabled()" 
                           id="Template6" value="Add Field" /><br />
                </div>
                <%  }%>


            </form:form>

            <p> <input type="button" value="Back" onClick="javascript: history.go(-1)"></p>
        </div>



    </div>


    <%@ include file="../footer.jsp" %>



